#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_HelpComponents/HelpComponents_Compress/HelpCompress_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_HelpComponents/HelpComponents_Compress/HelpCompress_Error.h"

//g++ -std=gnu++11 -Wall -g TestFor_Compress.cpp -o TestFor_Compress -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_HelpComponents -lNetEngine_BaseLib -lHelpComponents_Compress -Wl,-rpath=../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_HelpComponents,--disable-new-dtags

void UNCompressTest()
{
    XZIP xhFile = HelpCompress_File_OPen(_T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1.zip"));
    if (NULL == xhFile)
    {
        return;
    }
    int nCount = 0;
    HelpCompress_File_GetCount(xhFile, &nCount);

    BOOL bRet = HelpCompress_File_GoFirstFile(xhFile);
    while (bRet)
    {
        TCHAR tszExtDir[1204];
        HELPCOMPRESS_ZLIBINFO st_ZLibInfo;

        memset(tszExtDir, '\0', 1204);
        memset(&st_ZLibInfo, '\0', sizeof(HELPCOMPRESS_ZLIBINFO));
        HelpCompress_File_GetInfo(xhFile, &st_ZLibInfo);

        if (st_ZLibInfo.bIsFile)
        {
            _stprintf_s(tszExtDir, _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\%s"), st_ZLibInfo.tszFileName);
            HelpCompress_File_WriteFile(xhFile, tszExtDir);
        }
        else
        {
            _stprintf_s(tszExtDir, _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\%s"), st_ZLibInfo.tszFileName);
            //SystemApi_File_CreateMutilFolder(tszExtDir);
        }
        bRet = HelpCompress_File_GoNextFile(xhFile);
    }
    HelpCompress_File_UNClose(xhFile);
}
void CompressBuffer_Test()
{
    LPCTSTR lpszBuffer = _T("12345678901234567890123456789012345678901234567890");
    TCHAR tszEnBuffer[2048];
    TCHAR tszDeBuffer[2048];

    memset(tszEnBuffer, '\0', sizeof(tszEnBuffer));
    memset(tszDeBuffer, '\0', sizeof(tszDeBuffer));

    int nLen = _tcslen(lpszBuffer);
    DWORD dwEnLen = 2048;
    DWORD dwDeLen = 2048;

    if (!HelpCompress_Memory_Compress(lpszBuffer, nLen, tszEnBuffer, &dwEnLen, 4))
    {
        printf("%lX\n", HelpCompress_GetLastError());
        return;
    }

    if (!HelpCompress_Memory_UnCompress(tszEnBuffer, dwEnLen, tszDeBuffer, &dwDeLen))
    {
        printf("%lX\n", HelpCompress_GetLastError());
        return;
    }
}
void CompressFile_Test()
{
    XZIP xhFile = HelpCompress_File_Create(_T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1.zip"));
    HelpCompress_File_Add(xhFile, "NetEngine_SystemApi.dll", _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1\\NetEngine_SystemApi.dll"));
    HelpCompress_File_Add(xhFile, "zlibwapi.dll", _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1\\zlibwapi.dll"));
    HelpCompress_File_Add(xhFile, "123\\", NULL);
    HelpCompress_File_Add(xhFile, "123\\HelpComponents_Compress.dll", _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1\\123\\HelpComponents_Compress.dll"));
    HelpCompress_File_Add(xhFile, "123\\NetEngine_Algorithm.dll", _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1\\123\\NetEngine_Algorithm.dll"));
    HelpCompress_File_Close(xhFile);
}
int main()
{
    CompressBuffer_Test();
    return 0;
}


